package cn.dengta.webapp.trade.entity;

import java.util.List;

import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.user.model.Gender;
import cn.dengta.webapp.user.model.UserVipRule;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 个人VIP 权益配置
 *
 * @author zw
 * @since 2022-08-03
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName(value = "tr_user_vip_equity", autoResultMap = true)
public class UserVipEquity extends TimeBasedEntity {

	private static final long serialVersionUID = 1L;

	/** 权益名称 */
	private String equityName;
	/** VIP等级 1=VIP; */
	private Integer level;
	/** VIP性别; */
	private Gender gender;
	/** 权益图片 */
	private String image;
	/** 权益 */
	@TableField(value = "equity", typeHandler = JacksonTypeHandler.class)
	private JSONObject equity;
	/** 扩展数据 */
	@TableField(value = "extend", typeHandler = JacksonTypeHandler.class)
	private JSONObject extend;
	/** 业务状态 -1=禁用； 1=启用 */
	protected Integer status;

	/**
	 * 获取VIP配置信息
	 */
	public UserVipRule getUserVipConfig() {
		return this.equity.toJavaObject(UserVipRule.class);
	}

	public List<UserVipEquity.ExtendUserVipVO> getExtendUserVipVO() {
		return this.getExtend().getJSONArray("configs").toJavaList(UserVipEquity.ExtendUserVipVO.class);
	}

	public static final String EQUITY_NAME = "equity_name";
	public static final String LEVEL = "level";
	public static final String IMAGE = "image";
	public static final String SORT = "sort";
	public static final String EQUITY = "equity";
	public static final String EXTEND = "extend";
	public static final String GENDER = "gender";

	@Setter
	@Getter
	public static class ExtendUserVipVO {

		/** icon图片 */
		private String icon;
		/** 权益名 */
		private String name;

	}

}
